<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Bos项目," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="与未知的相遇，七分欢喜三分孤寂。  分页方法整理设计PageBean12345private Integer currentPage ;//当前页码private Integer pageSize;//每页显示的记录数量private DetachedCriteria detachedCriteria;//查询条件private Integer total;//总记录数private List">
<meta name="keywords" content="Bos项目">
<meta property="og:type" content="article">
<meta property="og:title" content="bos-three">
<meta property="og:url" content="http://yoursite.com/2017/05/29/bos-three/index.html">
<meta property="og:site_name" content="JokerLiang">
<meta property="og:description" content="与未知的相遇，七分欢喜三分孤寂。  分页方法整理设计PageBean12345private Integer currentPage ;//当前页码private Integer pageSize;//每页显示的记录数量private DetachedCriteria detachedCriteria;//查询条件private Integer total;//总记录数private List">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-05-29T09:45:10.162Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="bos-three">
<meta name="twitter:description" content="与未知的相遇，七分欢喜三分孤寂。  分页方法整理设计PageBean12345private Integer currentPage ;//当前页码private Integer pageSize;//每页显示的记录数量private DetachedCriteria detachedCriteria;//查询条件private Integer total;//总记录数private List">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/05/29/bos-three/"/>





  <title> bos-three | JokerLiang </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  








  <div style="display: none;">
    <script src="//s95.cnzz.com/z_stat.php?id=1260895995&web_id=1260895995" language="JavaScript"></script>
  </div>





  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">JokerLiang</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">永远年轻，永远热泪盈眶。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/05/29/bos-three/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="JokerLiang">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/me.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="JokerLiang">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="JokerLiang" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                bos-three
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2017-05-29T17:44:31+08:00">
                2017-05-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Bos项目/" itemprop="url" rel="index">
                    <span itemprop="name">Bos项目</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote>
<p>&#x4E0E;&#x672A;&#x77E5;&#x7684;&#x76F8;&#x9047;&#xFF0C;&#x4E03;&#x5206;&#x6B22;&#x559C;&#x4E09;&#x5206;&#x5B64;&#x5BC2;&#x3002;</p>
</blockquote>
<h2 id="&#x5206;&#x9875;&#x65B9;&#x6CD5;&#x6574;&#x7406;"><a href="#&#x5206;&#x9875;&#x65B9;&#x6CD5;&#x6574;&#x7406;" class="headerlink" title="&#x5206;&#x9875;&#x65B9;&#x6CD5;&#x6574;&#x7406;"></a>&#x5206;&#x9875;&#x65B9;&#x6CD5;&#x6574;&#x7406;</h2><h3 id="&#x8BBE;&#x8BA1;PageBean"><a href="#&#x8BBE;&#x8BA1;PageBean" class="headerlink" title="&#x8BBE;&#x8BA1;PageBean"></a>&#x8BBE;&#x8BA1;PageBean</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> Integer currentPage ;<span class="comment">//&#x5F53;&#x524D;&#x9875;&#x7801;</span></span><br><span class="line"><span class="keyword">private</span> Integer pageSize;<span class="comment">//&#x6BCF;&#x9875;&#x663E;&#x793A;&#x7684;&#x8BB0;&#x5F55;&#x6570;&#x91CF;</span></span><br><span class="line"><span class="keyword">private</span> DetachedCriteria detachedCriteria;<span class="comment">//&#x67E5;&#x8BE2;&#x6761;&#x4EF6;</span></span><br><span class="line"><span class="keyword">private</span> Integer total;<span class="comment">//&#x603B;&#x8BB0;&#x5F55;&#x6570;</span></span><br><span class="line"><span class="keyword">private</span> List rows; <span class="comment">//&#x5F53;&#x524D;&#x9875;&#x6240;&#x9700;&#x8981;&#x5C55;&#x793A;&#x7684;&#x8BB0;&#x5F55;&#x96C6;&#x5408;</span></span><br></pre></td></tr></table></figure>
<a id="more"></a>
<h3 id="&#x5206;&#x9875;&#x65B9;&#x6CD5;&#x7684;&#x62BD;&#x53D6;"><a href="#&#x5206;&#x9875;&#x65B9;&#x6CD5;&#x7684;&#x62BD;&#x53D6;" class="headerlink" title="&#x5206;&#x9875;&#x65B9;&#x6CD5;&#x7684;&#x62BD;&#x53D6;"></a>&#x5206;&#x9875;&#x65B9;&#x6CD5;&#x7684;&#x62BD;&#x53D6;</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">protected</span> PageBean pageBean = <span class="keyword">new</span> PageBean();</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setPage</span><span class="params">(Integer page)</span> </span>{</span><br><span class="line">		pageBean.setCurrentPage(page);</span><br><span class="line">	}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setRows</span><span class="params">(Integer rows)</span> </span>{</span><br><span class="line">		pageBean.setPageSize(rows);</span><br><span class="line">	}</span><br><span class="line"><span class="keyword">protected</span> DetachedCriteria dc =  <span class="keyword">null</span> ;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">ParameterizedType genericSuperclass = (ParameterizedType) <span class="keyword">this</span>.getClass().getGenericSuperclass();	</span><br><span class="line">Type[] actualTypeArguments = genericSuperclass.getActualTypeArguments();</span><br><span class="line">Class&lt;T&gt; entityClass = (Class&lt;T&gt;)actualTypeArguments[<span class="number">0</span>];</span><br><span class="line">dc = DetachedCriteria.forClass(entityClass);</span><br><span class="line">pageBean.setDetachedCriteria(dc);</span><br></pre></td></tr></table></figure>
<h3 id="Action&#x5199;&#x6CD5;"><a href="#Action&#x5199;&#x6CD5;" class="headerlink" title="Action&#x5199;&#x6CD5;"></a>Action&#x5199;&#x6CD5;</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> String <span class="title">pageQuery</span><span class="params">()</span></span>{</span><br><span class="line">	res.pageQuey(pageBean);</span><br><span class="line">	<span class="keyword">this</span>.java2Json(pageBean, </span><br><span class="line">				<span class="keyword">new</span> String[]{<span class="string">&quot;currentPage&quot;</span>,<span class="string">&quot;detachedCriteria&quot;</span>,<span class="string">&quot;pageSize&quot;</span>,<span class="string">&quot;subareas&quot;</span>});</span><br><span class="line">	<span class="keyword">return</span> NONE;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h3 id="Service&#x5199;&#x6CD5;"><a href="#Service&#x5199;&#x6CD5;" class="headerlink" title="Service&#x5199;&#x6CD5;"></a>Service&#x5199;&#x6CD5;</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">pageQuey</span><span class="params">(PageBean pageBean)</span> </span>{	</span><br><span class="line">		rg.pageQuery(pageBean);		</span><br><span class="line">	}</span><br></pre></td></tr></table></figure>
<h3 id="Dao&#x5199;&#x6CD5;"><a href="#Dao&#x5199;&#x6CD5;" class="headerlink" title="Dao&#x5199;&#x6CD5;"></a>Dao&#x5199;&#x6CD5;</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">pageQuery</span><span class="params">(PageBean pageBean)</span> </span>{</span><br><span class="line">	Integer currentPage = pageBean.getCurrentPage();</span><br><span class="line">	Integer pageSize = pageBean.getPageSize();</span><br><span class="line">	DetachedCriteria dc = pageBean.getDetachedCriteria();</span><br><span class="line">	<span class="comment">//&#x53D6;&#x51FA;Action&#x5C01;&#x88C5;&#x597D;&#x7684;&#x3002;</span></span><br><span class="line">	<span class="comment">//&#x8BBE;&#x7F6E;&#x67E5;&#x8BE2;&#x603B;&#x6570;&#x91CF;</span></span><br><span class="line">	dc.setProjection(Projections.rowCount());</span><br><span class="line">	List&lt;Long&gt; list = (List&lt;Long&gt;) getHibernateTemplate().findByCriteria(dc);</span><br><span class="line">	Long total = list.get(<span class="number">0</span>);</span><br><span class="line">	pageBean.setTotal(total.intValue());</span><br><span class="line">	<span class="comment">//&#x6E05;&#x695A;&#x4E0A;&#x9762;&#x8BBE;&#x7F6E;&#x7684;&#x51FD;&#x6570;</span></span><br><span class="line">	dc.setProjection(<span class="keyword">null</span>);</span><br><span class="line">	<span class="keyword">int</span> firstResult = (currentPage - <span class="number">1</span>) * pageSize;</span><br><span class="line">	<span class="keyword">int</span> maxResults  = pageSize;</span><br><span class="line">	List  rows = getHibernateTemplate().findByCriteria(dc, firstResult, maxResults);</span><br><span class="line">	pageBean.setRows(rows);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h2 id="jquery-OCUpload&#x4E00;&#x952E;&#x4E0A;&#x4F20;&#x63D2;&#x4EF6;&#x4F7F;&#x7528;"><a href="#jquery-OCUpload&#x4E00;&#x952E;&#x4E0A;&#x4F20;&#x63D2;&#x4EF6;&#x4F7F;&#x7528;" class="headerlink" title="jquery OCUpload&#x4E00;&#x952E;&#x4E0A;&#x4F20;&#x63D2;&#x4EF6;&#x4F7F;&#x7528;"></a>jquery OCUpload&#x4E00;&#x952E;&#x4E0A;&#x4F20;&#x63D2;&#x4EF6;&#x4F7F;&#x7528;</h2><h3 id="&#x9875;&#x9762;&#x63D0;&#x4F9B;&#x4EFB;&#x610F;&#x4E00;&#x4E2A;&#x5143;&#x7D20;"><a href="#&#x9875;&#x9762;&#x63D0;&#x4F9B;&#x4EFB;&#x610F;&#x4E00;&#x4E2A;&#x5143;&#x7D20;" class="headerlink" title="&#x9875;&#x9762;&#x63D0;&#x4F9B;&#x4EFB;&#x610F;&#x4E00;&#x4E2A;&#x5143;&#x7D20;"></a>&#x9875;&#x9762;&#x63D0;&#x4F9B;&#x4EFB;&#x610F;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">id</span>=<span class="string">&quot;myButton&quot;</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="&#x8C03;&#x7528;JS&#x65B9;&#x6CD5;"><a href="#&#x8C03;&#x7528;JS&#x65B9;&#x6CD5;" class="headerlink" title="&#x8C03;&#x7528;JS&#x65B9;&#x6CD5;"></a>&#x8C03;&#x7528;JS&#x65B9;&#x6CD5;</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{</span><br><span class="line">		<span class="comment">//&#x9875;&#x9762;&#x52A0;&#x8F7D;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x8C03;&#x7528;&#x63D2;&#x4EF6;&#x7684;upload&#x65B9;&#x6CD5;&#xFF0C;&#x52A8;&#x6001;&#x4FEE;&#x6539;&#x4E86;HTML&#x9875;&#x9762;&#x5143;&#x7D20;</span></span><br><span class="line">		$(<span class="string">&quot;#myButton&quot;</span>).upload({</span><br><span class="line">			action:<span class="string">&apos;xxx.action&apos;</span>,</span><br><span class="line">			name:<span class="string">&apos;myFile&apos;</span></span><br><span class="line">		});</span><br><span class="line">	});</span><br></pre></td></tr></table></figure>
<h3 id="&#x5728;Action&#x4E2D;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;File&#x7C7B;&#x578B;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x540D;&#x79F0;&#x548C;&#x4E0A;&#x4F20;&#x7684;&#x6587;&#x4EF6;&#x8F93;&#x5165;&#x6846;&#x540D;&#x79F0;&#x4E00;&#x81F4;"><a href="#&#x5728;Action&#x4E2D;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;File&#x7C7B;&#x578B;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x540D;&#x79F0;&#x548C;&#x4E0A;&#x4F20;&#x7684;&#x6587;&#x4EF6;&#x8F93;&#x5165;&#x6846;&#x540D;&#x79F0;&#x4E00;&#x81F4;" class="headerlink" title="&#x5728;Action&#x4E2D;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;File&#x7C7B;&#x578B;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x540D;&#x79F0;&#x548C;&#x4E0A;&#x4F20;&#x7684;&#x6587;&#x4EF6;&#x8F93;&#x5165;&#x6846;&#x540D;&#x79F0;&#x4E00;&#x81F4;"></a>&#x5728;Action&#x4E2D;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;File&#x7C7B;&#x578B;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x540D;&#x79F0;&#x548C;&#x4E0A;&#x4F20;&#x7684;&#x6587;&#x4EF6;&#x8F93;&#x5165;&#x6846;&#x540D;&#x79F0;&#x4E00;&#x81F4;</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RegionAction</span> <span class="keyword">extends</span> <span class="title">BaseAction</span>&lt;<span class="title">Region</span>&gt;</span>{</span><br><span class="line">	<span class="comment">//&#x5C5E;&#x6027;&#x9A71;&#x52A8;&#xFF0C;&#x63A5;&#x6536;&#x4E0A;&#x4F20;&#x7684;&#x6587;&#x4EF6;</span></span><br><span class="line">	<span class="keyword">private</span> File regionFile;</span><br></pre></td></tr></table></figure>
<h2 id="&#x6587;&#x4EF6;&#x4E0B;&#x8F7D;"><a href="#&#x6587;&#x4EF6;&#x4E0B;&#x8F7D;" class="headerlink" title="&#x6587;&#x4EF6;&#x4E0B;&#x8F7D;"></a>&#x6587;&#x4EF6;&#x4E0B;&#x8F7D;</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">HSSFSheet sheet = hf.createSheet(<span class="string">&quot;&#x5206;&#x533A;&#x6570;&#x636E;&quot;</span>);</span><br><span class="line">String filename = <span class="string">&quot;&#x5206;&#x533A;&#x6570;&#x636E;.xls&quot;</span>;</span><br><span class="line">String mimeType = ServletActionContext.getServletContext().getMimeType(filename);</span><br><span class="line">ServletOutputStream outputStream = ServletActionContext.getResponse().getOutputStream();</span><br><span class="line">ServletActionContext.getResponse().setContentType(mimeType);</span><br><span class="line"><span class="comment">//&#x83B7;&#x53D6;&#x6D4F;&#x89C8;&#x5668;&#x7C7B;&#x578B;</span></span><br><span class="line">String agent = ServletActionContext.getRequest().getHeader(<span class="string">&quot;User-Agent&quot;</span>);</span><br><span class="line"><span class="comment">//&#x8BB2;&#x6587;&#x4EF6;&#x540D;&#x5B57;&#x8FDB;&#x884C;&#x7F16;&#x7801;</span></span><br><span class="line">filename = FileUtils.encodeDownloadFilename(filename, agent);</span><br><span class="line">ServletActionContext.getResponse().setHeader(<span class="string">&quot;content-disposition&quot;</span>, <span class="string">&quot;attachment;filename=&quot;</span>+filename);</span><br><span class="line">hf.write(outputStream);</span><br><span class="line"><span class="keyword">return</span> NONE;</span><br></pre></td></tr></table></figure>
<h2 id="apachePoi&#x6280;&#x672F;"><a href="#apachePoi&#x6280;&#x672F;" class="headerlink" title="apachePoi&#x6280;&#x672F;"></a>apachePoi&#x6280;&#x672F;</h2><ul>
<li>POI&#x63D0;&#x4F9B;API&#x7ED9;Java&#x7A0B;&#x5E8F;&#x5BF9;Microsoft Office&#x683C;&#x5F0F;&#x6863;&#x6848;&#x8BFB;&#x548C;&#x5199;&#x7684;&#x529F;&#x80FD;<h3 id="XLS&#x8BFB;&#x5230;JAVA"><a href="#XLS&#x8BFB;&#x5230;JAVA" class="headerlink" title="XLS&#x8BFB;&#x5230;JAVA"></a>XLS&#x8BFB;&#x5230;JAVA</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">fn1</span><span class="params">()</span> <span class="keyword">throws</span> FileNotFoundException, IOException</span>{</span><br><span class="line">	String files = <span class="string">&quot;C:\\Users\\JokerLiang\\Desktop\\&#x533A;&#x57DF;&#x5BFC;&#x5165;&#x6D4B;&#x8BD5;&#x6570;&#x636E;.xls&quot;</span>;</span><br><span class="line">		HSSFWorkbook hf = <span class="keyword">new</span> HSSFWorkbook(<span class="keyword">new</span> FileInputStream(<span class="keyword">new</span> File(files)));</span><br><span class="line">		HSSFSheet hs = hf.getSheetAt(<span class="number">0</span>);</span><br><span class="line">		<span class="keyword">for</span>(Row row : hs){</span><br><span class="line">			<span class="keyword">if</span>(row.getRowNum()==<span class="number">1</span>){</span><br><span class="line">				<span class="comment">//&#x5982;&#x679C;&#x662F;&#x7B2C;&#x4E00;&#x884C;&#x6807;&#x9898;&#x680F;&#x5219;&#x4E0D;&#x6253;&#x5370;&#x3002;</span></span><br><span class="line">				<span class="keyword">continue</span> ;</span><br><span class="line">			}</span><br><span class="line">			System.out.println();</span><br><span class="line">			<span class="keyword">for</span>(Cell cell : row){</span><br><span class="line">				System.out.print(cell);</span><br><span class="line">			}</span><br><span class="line">		}</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="JAVA&#x5199;&#x5230;XLS"><a href="#JAVA&#x5199;&#x5230;XLS" class="headerlink" title="JAVA&#x5199;&#x5230;XLS"></a>JAVA&#x5199;&#x5230;XLS</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> String <span class="title">exportXls</span><span class="params">()</span> <span class="keyword">throws</span> IOException</span>{</span><br><span class="line">	<span class="comment">//&#x8C03;&#x7528;SERVICE&#x67E5;&#x8BE2;&#x5206;&#x533A;&#x6570;&#x636E;</span></span><br><span class="line">	List&lt;Subarea&gt; sbs = ses.findAll();</span><br><span class="line">	HSSFWorkbook hf = <span class="keyword">new</span> HSSFWorkbook();</span><br><span class="line">	<span class="comment">//&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6807;&#x7B7E;&#x9875;</span></span><br><span class="line">	HSSFSheet sheet = hf.createSheet(<span class="string">&quot;&#x5206;&#x533A;&#x6570;&#x636E;&quot;</span>);</span><br><span class="line">	<span class="comment">//&#x521B;&#x5EFA;&#x7B2C;&#x4E00;&#x6392;&#x6807;&#x9898;</span></span><br><span class="line">	HSSFRow oneRow = sheet.createRow(<span class="number">0</span>);</span><br><span class="line">	oneRow.createCell(<span class="number">0</span>).setCellValue(<span class="string">&quot;&#x5206;&#x533A;&#x7F16;&#x53F7;&quot;</span>);</span><br><span class="line">	oneRow.createCell(<span class="number">1</span>).setCellValue(<span class="string">&quot;&#x5F00;&#x59CB;&#x7F16;&#x53F7;&quot;</span>);</span><br><span class="line">	oneRow.createCell(<span class="number">2</span>).setCellValue(<span class="string">&quot;&#x7ED3;&#x675F;&#x7F16;&#x53F7;&quot;</span>);</span><br><span class="line">	oneRow.createCell(<span class="number">3</span>).setCellValue(<span class="string">&quot;&#x4F4D;&#x7F6E;&#x4FE1;&#x606F;&quot;</span>);</span><br><span class="line">	oneRow.createCell(<span class="number">4</span>).setCellValue(<span class="string">&quot;&#x7701;&#x5E02;&#x533A;&quot;</span>);</span><br><span class="line">	<span class="keyword">for</span>(Subarea s : sbs){</span><br><span class="line">		HSSFRow row = sheet.createRow(sheet.getLastRowNum()+<span class="number">1</span>);</span><br><span class="line">		row.createCell(<span class="number">0</span>).setCellValue(s.getId());</span><br><span class="line">		row.createCell(<span class="number">1</span>).setCellValue(s.getStartnum());</span><br><span class="line">		row.createCell(<span class="number">2</span>).setCellValue(s.getEndnum());</span><br><span class="line">		row.createCell(<span class="number">3</span>).setCellValue(s.getPosition());</span><br><span class="line">		row.createCell(<span class="number">4</span>).setCellValue(s.getRegion().getName());</span><br><span class="line"></span><br><span class="line">	}</span><br><span class="line">	</span><br><span class="line">	<span class="comment">//&#x4F7F;&#x7528;&#x8F93;&#x51FA;&#x6D41;&#xFF0C;&#x8FDB;&#x884C;&#x6587;&#x4EF6;&#x7684;&#x4E0B;&#x8F7D;&#xFF08;1&#x4E2A;&#x5934;&#xFF0C;&#x4E24;&#x4E2A;&#x6D41;&#xFF09;</span></span><br><span class="line">	String filename = <span class="string">&quot;&#x5206;&#x533A;&#x6570;&#x636E;.xls&quot;</span>;</span><br><span class="line">	String mimeType = ServletActionContext.getServletContext().getMimeType(filename);</span><br><span class="line">	ServletOutputStream outputStream = ServletActionContext.getResponse().getOutputStream();</span><br><span class="line">	ServletActionContext.getResponse().setContentType(mimeType);</span><br><span class="line">	<span class="comment">//&#x83B7;&#x53D6;&#x6D4F;&#x89C8;&#x5668;&#x7C7B;&#x578B;</span></span><br><span class="line">	String agent = ServletActionContext.getRequest().getHeader(<span class="string">&quot;User-Agent&quot;</span>);</span><br><span class="line">	<span class="comment">//&#x8BB2;&#x6587;&#x4EF6;&#x540D;&#x5B57;&#x8FDB;&#x884C;&#x7F16;&#x7801;</span></span><br><span class="line">	filename = FileUtils.encodeDownloadFilename(filename, agent);</span><br><span class="line">	ServletActionContext.getResponse().setHeader(<span class="string">&quot;content-disposition&quot;</span>, <span class="string">&quot;attachment;filename=&quot;</span>+filename);</span><br><span class="line">	hf.write(outputStream);</span><br><span class="line">	<span class="keyword">return</span> NONE;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Bos项目/" rel="tag"># Bos项目</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/05/23/bos-two/" rel="next" title="bos-two">
                <i class="fa fa-chevron-left"></i> bos-two
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/06/01/bos-four/" rel="prev" title="bos-four">
                bos-four <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/me.jpg"
               alt="JokerLiang" />
          <p class="site-author-name" itemprop="name">JokerLiang</p>
          <p class="site-description motion-element" itemprop="description">永远年轻，永远热泪盈眶。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">61</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/LoverJoker" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.zhihu.com/people/lover-easy-7/activities" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/2292572142/profile?rightmod=1&wvr=6&mod=personinfo" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Friends
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.knight.ac.cn/" title="Knight" target="_blank">Knight</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://lzllzl.cn/" title="Zayvion" target="_blank">Zayvion</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://chen97.com/" title="Chens" target="_blank">Chens</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#分页方法整理"><span class="nav-number">1.</span> <span class="nav-text">分页方法整理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#设计PageBean"><span class="nav-number">1.1.</span> <span class="nav-text">设计PageBean</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#分页方法的抽取"><span class="nav-number">1.2.</span> <span class="nav-text">分页方法的抽取</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Action写法"><span class="nav-number">1.3.</span> <span class="nav-text">Action写法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Service写法"><span class="nav-number">1.4.</span> <span class="nav-text">Service写法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Dao写法"><span class="nav-number">1.5.</span> <span class="nav-text">Dao写法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jquery-OCUpload一键上传插件使用"><span class="nav-number">2.</span> <span class="nav-text">jquery OCUpload一键上传插件使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#页面提供任意一个元素"><span class="nav-number">2.1.</span> <span class="nav-text">页面提供任意一个元素</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#调用JS方法"><span class="nav-number">2.2.</span> <span class="nav-text">调用JS方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在Action中提供一个File类型的属性，名称和上传的文件输入框名称一致"><span class="nav-number">2.3.</span> <span class="nav-text">在Action中提供一个File类型的属性，名称和上传的文件输入框名称一致</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#文件下载"><span class="nav-number">3.</span> <span class="nav-text">文件下载</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#apachePoi技术"><span class="nav-number">4.</span> <span class="nav-text">apachePoi技术</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#XLS读到JAVA"><span class="nav-number">4.1.</span> <span class="nav-text">XLS读到JAVA</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#JAVA写到XLS"><span class="nav-number">4.2.</span> <span class="nav-text">JAVA写到XLS</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">JokerLiang</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	




  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

  


</body>
</html>
